package com.fudan.es.aggs;

import org.elasticsearch.search.aggregations.AggregationBuilder;

import com.fudan.es.aggs.entity.AggsList;

public class AggsBuilder {

	private AggsList aggsList;
	private AggregationBuilder aggregationBuilder;

	private AggsBuilder(AggregationBuilder aggregationBuilder) {
		this.aggregationBuilder = aggregationBuilder;
		aggsList = AggsList.build();
		aggsList.addAggs(aggregationBuilder.getName());
	}
	public static AggsBuilder build(AggregationBuilder aggregationBuilder) {
		return new AggsBuilder(aggregationBuilder);
	}

	public AggsBuilder aggs(AggsBuilder aggsBuilder) {
		this.aggregationBuilder = aggsBuilder.getAggregationBuilder();
		aggsList.addAggs(aggsBuilder.getAggsList());
		return this;
	}

	public AggsBuilder subAggs(AggsBuilder aggsBuilder) {
		aggsList.addAggs(aggsBuilder.getAggsList());
		this.aggregationBuilder.subAggregation(aggsBuilder.getAggregationBuilder());
		return this;
	}
	public AggsList getAggsList() {
		return aggsList;
	}
	public void setAggsList(AggsList aggsList) {
		this.aggsList = aggsList;
	}
	public AggregationBuilder getAggregationBuilder() {
		return aggregationBuilder;
	}
	public void setAggregationBuilder(AggregationBuilder aggregationBuilder) {
		this.aggregationBuilder = aggregationBuilder;
	}


}
